import request from '../utils/request'

// 定义资讯数据类型
export interface Announcement {
  announcementId: number
  title: string
  name: string
  classification: string
  createTime: string
  text: string
}

// 获取所有心理资讯
export const getAllAnnouncements = () => {
  return request({
    url: '/announcement-info/list',
    method: 'get'
  })
}

// 获取心理资讯详情
export const getAnnouncementDetail = (announcementId: number) => {
  return request<Announcement>({
    url: `/announcement-info/get/${announcementId}`,
    method: 'get'
  })
}
// 根据分类获取心理资讯
export const getAnnouncementsByClassification = (classification: string) => {
  return request({
    url: '/announcement-info/get/classification',
    method: 'get',
    params: { classification }
  })
}

// 获取作者的其他文章
export const getAuthorAnnouncements = (name: string, limit: number = 5) => {
  return request<Announcement[]>({
    url: '/announcement-info/list/creator',
    method: 'get',
    params: { name, limit }
  })
}

// 资讯分类选项
export const classificationOptions = [
  { label: '情感困扰', value: 'emotion' },
  { label: '学业压力', value: 'study' },
  { label: '职场压力', value: 'work' },
  { label: '家庭关系', value: 'family' },
  { label: '人际关系', value: 'social' },
  { label: '心理障碍', value: 'disorder' }
]

// 分类标签类型映射
export const classificationTypeMap = {
  'emotion': 'danger',
  'study': 'warning',
  'work': 'info',
  'family': 'success',
  'social': 'primary',
  'disorder': 'error'
}

// 分类标签文本映射
export const classificationLabelMap = {
  'emotion': '情感困扰',
  'study': '学业压力',
  'work': '职场压力',
  'family': '家庭关系',
  'social': '人际关系',
  'disorder': '心理障碍'
}

